package com.hb.core.config;

import com.hb.application.cache.TokenCache;
import com.hb.core.filter.AccountContextFilter;
import com.hb.core.filter.ThreadLocalContextFilter;
import com.hb.domain.user.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @projectName: zhb-frame-build
 * @author: zhouhaizhi
 * @createTime: 2021/8/27 16:09
 * @version:1.0
 */
@Configuration
public class FilterRegisterConfig {

    @Bean
    public FilterRegistrationBean<ThreadLocalContextFilter> threadLocalContextFilter() {
        FilterRegistrationBean<ThreadLocalContextFilter> registrationBean = new FilterRegistrationBean<ThreadLocalContextFilter>();
        registrationBean.setFilter(new ThreadLocalContextFilter());
        registrationBean.setOrder(-100);
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private TokenCache tokenCache;

    @Bean
    public FilterRegistrationBean<AccountContextFilter> accountContextFilter() {
        FilterRegistrationBean<AccountContextFilter> registrationBean = new FilterRegistrationBean<AccountContextFilter>();
        registrationBean.setFilter(new AccountContextFilter(sysUserService, tokenCache));
        registrationBean.setOrder(-101);
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }
}
